package com.joekai.view_demo.main;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.joekai.view_demo.R;
import com.joekai.view_demo.main.MainItem;

import java.util.List;

public class MainAdapter extends ArrayAdapter<MainItem> {
    private int resourceId;
    ListView lv;

    public MainAdapter(@NonNull Context context, int resource, @NonNull List<MainItem> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        //根据position获取待显示的Fruit实例
        MainItem item = getItem(position);
        //获取子视图控件实例
        View view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
        TextView fruitName = (TextView) view.findViewById(R.id.txv_);
        fruitName.setText(item.key);
        return view;
    }
}
